<?php
// Redis 消费任务示例
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->select(1);

$streamKey = 'task:stream:processing';
$groupName = 'my_group';
$consumerName = 'my_consumer';

$tasks = $redis->xReadGroup($groupName, $consumerName, [$streamKey => '>'], 1, 1000);
if (!empty($tasks[$streamKey])) {
    foreach ($tasks[$streamKey] as $msgId => $fields) {
        echo "收到任务: $msgId\n";
        print_r($fields);

        // 处理任务...

        // 处理完成后ack
        $redis->xAck($streamKey, $groupName, [$msgId]);
        echo "已确认任务: $msgId\n";
    }
} else {
    echo "暂无新任务可消费。\n";
} 